Line data Source code
1 : #include "CleaningController.hpp"
2 : #include "ICleaningMotor.hpp"
3 : #include "CleaningLevel.hpp"
4 :
5 82 : CleaningController::CleaningController(ICleaningMotor& motor, int timerDurationMs)
6 82 : : motor_(motor), timer_(*this, timerDurationMs), active_(false), boosting_(false) {}
7 :
8 52 : void CleaningController::startCleaning() {
9 52 : if (active_) return;
10 52 : active_ = true;
11 52 : timer_.stop();
12 52 : boosting_ = false;
13 52 : motor_.startCleaning(CleaningLevel::NORMAL);
14 52 : }
15 :
16 24 : void CleaningController::stopCleaning() {
17 24 : if (!active_) return;
18 24 : active_ = false;
19 24 : timer_.stop();
20 24 : boosting_ = false;
21 24 : motor_.stopCleaning();
22 24 : }
23 :
24 9 : void CleaningController::boostCleaning() {
25 9 : if (!active_) return;
26 8 : if (boosting_) {
27 1 : timer_.reset();
28 1 : } else {
29 7 : boosting_ = true;
30 7 : motor_.startCleaning(CleaningLevel::HIGH);
31 7 : timer_.start();
32 : }
33 9 : }
34 :
35 2 : void CleaningController::onExpired() {
36 2 : boosting_ = false;
37 2 : motor_.startCleaning(CleaningLevel::NORMAL);
38 2 : }
39 :
40 3 : void CleaningController::normalizePower() {
41 3 : if (!active_) return;
42 2 : if (!boosting_) return;
43 1 : timer_.stop();
44 1 : boosting_ = false;
45 1 : motor_.startCleaning(CleaningLevel::NORMAL);
46 3 : }
|